package com.jin.firstspring.controller;

import com.jin.firstspring.controller.model.Course;
import com.jin.firstspring.controller.service.CourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/course")
public class CourseController {
    private static Logger logger = LoggerFactory.getLogger(CourseController.class);
    private CourseService courseService;
    @Autowired
    public void setCourseService(CourseService courseService) {
        this.courseService = courseService;
    }

    @RequestMapping(value = "/view", method = RequestMethod.GET)
    private String viewCourse(@RequestParam("courseId") Integer courseId, Model model) {
        Course course = courseService.getCoursebyId(courseId);
        model.addAttribute(course);
        logger.debug("你大爷的ID" + courseId);
        return "course_json";
    }
    @RequestMapping(value = "/view/{courseId}", method = RequestMethod.GET)
    private String viewCourse2(@PathVariable("courseId") Integer courseId, Model model) {
        Course course = courseService.getCoursebyId(courseId);
        model.addAttribute(course);
        logger.debug("你大爷的ID" + courseId);
        return "course_json";
    }
    @RequestMapping(value = "/{courseId}" ,method = RequestMethod.GET)
    public @ResponseBody Course getJson(@PathVariable Integer courseId){
        return courseService.getCoursebyId(courseId);

    }
}
